package dao

import (
	"fmt"
	"github.com/gogf/gf/database/gdb"
	"github.com/gogf/gf/frame/g"
)

var T_hzfgw_node_deliver = t_hzfgw_node_deliver{}

type t_hzfgw_node_deliver struct {
}

func (a *t_hzfgw_node_deliver) Exits(addr string, sn string) (exits bool, err error) {
	db := g.DB(g.Cfg().GetString("custom.db_name"))
	model := db.Model("t_hzfgw_node_deliver")
	result, error := model.Where(fmt.Sprintf(" addr='%s' and sn='%s' ", addr, sn)).Count()
	if error != nil {
		err = error
	} else {
		if result > 0 {
			exits = true
		} else {
			exits = false
		}
	}
	return exits, err
}

func (a *t_hzfgw_node_deliver) GetList(where ...string) (list gdb.List, err error) {
	db := g.DB(g.Cfg().GetString("custom.db_name"))
	model := db.Model("t_hzfgw_node_deliver")
	if len(where) == 0 {
	} else {
		model = model.Where(where[0])
	}
	res, err := model.All()
	return res.List(), err
}

/*func (a *t_hzfgw_node_deliver) Save(data interface{}) (isOk bool,err error) {
	db:=g.DB(g.Cfg().GetString("custom.db_name"))
	_,err = db.Model("t_hzfgw_node_deliver").Data(data).Save()
	if err!=nil{
		return false, err
	}else{
		return true,nil
	}
}*/

func (a *t_hzfgw_node_deliver) Update(data interface{}) (isOk bool, err error) {
	db := g.DB(g.Cfg().GetString("custom.db_name"))
	_, err = db.Model("t_hzfgw_node_deliver").Data(data).Save()
	if err != nil {
		return false, err
	} else {
		return true, nil
	}
}

func (a *t_hzfgw_node_deliver) Insert(data interface{}) (isOk bool, err error) {
	db := g.DB(g.Cfg().GetString("custom.db_name"))
	_, err = db.Model("t_hzfgw_node_deliver").Data(data).Insert()
	if err != nil {
		return false, err
	} else {
		return true, nil
	}
}
